﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MyHealthOnline.Business;
using MyHealthOnline.Dal.Generated.EntityClasses;

namespace MyHealthOnline.Specialist.Controls
{
    public partial class NextAppointment : System.Web.UI.UserControl
    {
        public int ConsultId
        {
            get
            {
                if (ViewState["ConsultId"] == null)
                {
                    return -1;
                }
                return Convert.ToInt32(ViewState["ConsultId"].ToString());
            }
            set
            {
                ViewState["ConsultId"] = value;
            }
        }
        public ConsultEntity Consult
        {
            get
            {
                return ConsultBusiness.GetConsult(ConsultId);
            }
        }
        
        protected void Page_Load(object sender, EventArgs e)
        {
            txtNextDate.Text = DateTime.Now.Date.ToShortDateString();
        }

        protected void btnNextDate_Click(object sender, EventArgs e)
        {
            ConsultBusiness.SaveConsult(Consult, "", "", "Appointment");

            AppProposalBusiness.AddAppointment(
                ConsultId,
                txtNextDateMessage.Text,
                txtNextDate.Text,
                "");

            txtNextDate.Text = DateTime.Now.ToShortDateString();
            txtNextDateMessage.Text = "";

            WebServiceHO webService = new WebServiceHO();
            webService.Notify(Consult.Specialist.Email, Consult.Pacient.Email,
                "You have a new appointment for your consult with " + Consult.Specialist.Name + " on the " + txtNextDate.Text,
                "New appointment");

        }

        protected void txtNextDate_TextChanged(object sender, EventArgs e)
        {
            txtNextDateMessage.Text = string.Format("I will return to the consult on the date of {0}", txtNextDate.Text);
        }
    }
}